package org.cook.utils.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;

public class FileUtils {

	public static String getFileContent(File file) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(file));
		
		StringBuilder content = new StringBuilder();
		String line = null;
		while ((line = br.readLine()) != null) {
			content.append(line).append("\n");
		}
		br.close();
		
		return content.toString();
	}
	
	public static String getFileContent(String filePath) throws IOException {
		return getFileContent(new File(filePath));
	}
	
	public static String getResourcePath(String resource) {
		URL url = FileUtils.class.getClassLoader().getResource(resource);
		return url == null ? "" : url.getPath();
	}
	
}
